<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<span style="font-size: 18px;font-weight: 600">《{{formTitle}}》表单记录</span>
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.bpmRunNo" placeholder="流水号" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" :params="{formId:this.formId}" row-key="runId" border drag-sort stripe>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column v-for="item in fieldList" :key="item.prop" :label="item.label" :prop="item.prop" :width="item.width" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="170">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show_log(scope.row, scope.$index)" v-if="dataLogFlag=='1'">日志</el-button>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-popconfirm title="确定编辑表单数据吗？" @confirm="table_edit(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">编辑</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>

			</scTable>
		</el-main>
	</el-container>
	<datarecordedit v-if="dialog.save" :field-list="this.fieldList" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></datarecordedit>
</template>

<script>
import Datarecordedit from "@/views/doc/setting/bpmform/datarecordedit";
export default {
	name: 'Bpm Data Record',
	components: {
		Datarecordedit
	},
	data() {
		return {
			dialog: {
				save: false,
			},
			fieldList:[],
			apiObj: this.$API.bpm.bpmForm.getAllBpmFormDataForRecord,
			selection: [],
			formId:this.$route.query.formId,
			dataLogFlag:this.$route.query.dataLogFlag,
			formTitle:this.$route.query.formTitle,
			search: {
				bpmRunNo: ""
			}
		}
	},
	mounted() {
		this.getFormDataFieldTitle();
	},
	methods: {
		async getFormDataFieldTitle(){
			var res = await this.$API.bpm.bpmForm.getFormDataFieldTitle.get({formId: this.formId});
			if (res.code == 200) {
				this.fieldList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//编辑
		table_edit(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open().setData(row)
			})
		},
		//查看
		table_show(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open("show").setData(row)
			})
		},
		//查看
		table_show_log(row) {
			this.$nextTick(() => {
				this.$router.replace({
					path: '/doc/setting/bpmform/datalogrecord',
					query:{
						formId:this.formId,
						runId:row.run_id,
						formTitle:this.formTitle
					}
				})
			})
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		}
	}
}
</script>

<style>
</style>
